//
//  FunctionXJViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-10-31.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "FunctionXJViewController.h"
#import "F37ViewController.h"
#import "GreenHuaViewController.h"
#import "SecondZhuangXiuViewController.h"
#import "EmergencyViewController.h"
#import "EverydayPollingViewController.h"
#import "F37ViewController.h"
#import "CoffeeViewController.h"
#import "ChenJianViewController.h"
@interface FunctionXJViewController ()
{
    UIImageView *weakBlackView;
}
@end

@implementation FunctionXJViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [Appinfomation shareIstance].strongXunJianCount = 10247;
    self.title = @"运作部巡检";
    NSArray *array = @[@"日常巡检",@"日常晨检",@"37F巡检",@"外围绿化巡检",@"餐厅日常巡检",@"咖吧日常巡检",@"突发事件记录",@"2次装修查看"];
    [self addArray:array];
    [self addBlackView];
}
- (void)addBlackView
{
    UIImage *blackImage = [UIImage imageNamed:@"黑底1"];
    weakBlackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    weakBlackView.userInteractionEnabled = YES;
    weakBlackView.image = blackImage;
    [self.view addSubview:weakBlackView];

    UIImage *whiteIG = [UIImage imageNamed:@"工程部白底"];
    UIImageView *whiteView1 = [[UIImageView alloc]initWithImage:whiteIG];
    whiteView1.frame = CGRectMake((scrennWidth - whiteIG.size.width)/2, (screenHeight - whiteIG.size.height)/2, whiteIG.size.width, whiteIG.size.height);
    [whiteView1 setUserInteractionEnabled:YES];
    [weakBlackView addSubview:whiteView1];
    
    UILabel *weakLB = [UILabel new];
    weakLB.text = @"日常巡检";
    weakLB.font = [UIFont systemFontOfSize:36];
    CGSize size = [weakLB.text sizeWithFont:weakLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    weakLB.frame = CGRectMake((whiteIG.size.width - size.width)/2, 50, size.width, size.height);
    [whiteView1 addSubview:weakLB];
    
    UIImage *btnImage = [UIImage imageNamed:@"资料库按钮"];
    UIImage *closeImage = [UIImage imageNamed:@"删除"];
    UIButton *celsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [celsBtn setImage:closeImage forState:UIControlStateNormal];
    celsBtn.frame = CGRectMake(whiteIG.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [celsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView1 addSubview:celsBtn];
    for (int i = 0 ; i < 2; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.tag = 100+i;
        btn.frame = CGRectMake((whiteIG.size.width - btnImage.size.width*2)/3*(i%2+1)+(btnImage.size.width)*(i%2), (whiteIG.size.height - weakLB.frame.origin.y - weakLB.frame.size.height - btnImage.size.height*2)/3*(i/2+1) + btnImage.size.height*(i/2) + weakLB.frame.size.height + weakLB.frame.origin.y, btnImage.size.width, btnImage.size.height);
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 100)
        {
            btnLb.text = @"日常巡检（一）";
        }
        else if(btn.tag == 101)
        {
            btnLb.text = @"日常巡检（二）";
        }
        btnLb.textColor = [UIColor whiteColor];
        size = [@"啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        [btnLb setNumberOfLines:0];
        [btnLb setTextAlignment:1];
        btnLb.backgroundColor = [UIColor clearColor];
        if (btn.tag == 102)
        {
            btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*3)/2, size.width, size.height*3);
        }
        else
        {
            btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*2)/2, size.width, size.height*2);
        }
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(ruodian:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView1 addSubview:btn];
    }
    weakBlackView.hidden = YES;

}
- (void)closeV
{
    weakBlackView.hidden = 1;
    self.navigationController.navigationBar.hidden = 0;
}
- (void)clicked:(UIButton*)btn
{
    [Appinfomation shareIstance].strongXunJianCount = btn.tag;
    _openFrid = 0;
    switch (btn.tag) {
        case 0:
        {
            weakBlackView.hidden = NO;
            self.navigationController.navigationBar.hidden = YES;
        }
            break;
        case 1:
        {
             ChenJianViewController *everyV = [ChenJianViewController new];
            _openFrid = 1;
            [self.navigationController pushViewController:everyV animated:YES];
            everyV.functionDelegate = self;
        }
            break;
        case 2:
        {
            F37ViewController *FView = [F37ViewController new];
            [self.navigationController pushViewController:FView animated:YES];
        }
            break;
        case 3:
        {
            GreenHuaViewController *green = [GreenHuaViewController new];
            [self.navigationController pushViewController:green animated:YES];
        }
            break;
        case 4:
        {
            EverydayPollingViewController *canteen = [EverydayPollingViewController new];
            [self.navigationController pushViewController:canteen animated:YES];
        }
            break;
        case 5:
        {//咖啡
            CoffeeViewController *coffee =[[CoffeeViewController alloc]init];
            [self.navigationController pushViewController:coffee animated:YES];
        }
            break;
        case 6:
        {
            EmergencyViewController *emeV = [EmergencyViewController new];
            [self.navigationController pushViewController:emeV animated:YES];
        }
            break;
        case 7:
        {
            SecondZhuangXiuViewController *secondV  = [SecondZhuangXiuViewController new];
            [self.navigationController pushViewController:secondV animated:YES];
        }
            break;
        case 8:
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
            
        default:
            break;
    }
    
}

- (void)ruodian:(UIButton *)sender
{
    EverydayPollingViewController *everyV = [EverydayPollingViewController new];
    _openFrid = 1;
    everyV.functionDelegate = self;
    [self.navigationController pushViewController:everyV animated:YES];
    [Appinfomation shareIstance].strongXunJianCount = sender.tag;
    self.navigationController.navigationBar.hidden = NO;
    weakBlackView.hidden = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
